package com.example.yc23.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.yc23.demo.pojo.Film;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Repository
public interface FilmMapper extends BaseMapper<Film> {
    @Insert("INSERT INTO review VALUE(NULL,#{param1},#{param2},#{param3},1,#{param4})")
    int insertReview(Integer userId, Integer filmId, String content, Date time);
    //如何判断某个用户是否给某个电影打过分
    @Select("select count(*) from score where user_id = #{param1} and film_id = #{param2}")
    Integer selectCountScore(Integer userId,Integer filmId);
    //添加一个打分记录
    @Insert("insert into score value(null,#{param1},#{param2},#{param3})")
    Integer insertScore(Integer userId,Integer filmId,Integer stars);
    //更新打分
    @Update("update score set star=#{param3} where  user_id = #{param1} and film_id =#{param2}")
    Integer updateScore(Integer userId,Integer filmId,Integer stars);

    //使用电影ID查询影人信息
    List<HashMap> selectMakerInfo(@Param("filmId") Integer filmId);
    //查询几人评分
    Integer selectScoreTotal(@Param("filmId") Integer filmId);
    //评分百分比
    List<HashMap> selectScorePrecent(@Param("filmId") Integer filmId);
    //通过MySQL函数计算电影评分
    Float selectAvgScoreById(@Param("filmId") Integer filmId);
    //在影片影人表中添加一条数据
    @Insert("insert into film_maker value(null,#{fid},#{mid},#{job})")
    int insertFilmMarker(@Param("fid") Integer filmId,@Param("mid") Integer makerId,@Param("job") String job);
    //返回影片演职人员出现的次数(只有为零的时候才能添加)
    @Select("select count(*) from film_maker where film_id=#{fid} and maker_id = #{mid} and job=#{job}")
    int countFilmmaker(@Param("fid") Integer filmId,@Param("mid") Integer makerId,@Param("job") String job);

}
